package com.why.whyojbackendmodel.vo;

import cn.hutool.json.JSONUtil;

import com.why.whyojbackendmodel.dto.questionsubmit.JudgeInfo;
import com.why.whyojbackendmodel.entity.QuestionSubmit;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;

/**
 *
 *
 *
 *
 **/
@Data
public class QuestionSubmitQueryVO implements Serializable {


    private Long id;

    /**
     * 编程语言
     */
    private String language;

    /**
     * 用户代码
     */
    private String code;

    /**
     * 判题信息（jason对象）
     */
    private JudgeInfo judgeInfo;

    /**
     * 提交状态：0-待判题，1-判题中，2-成功，3-失败
     */
    private Integer status;

    private QuestionVO questionVO;
    
    private UserVO userVO;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;



    // 全部属性可转
    public static QuestionSubmit voToObj(QuestionSubmitQueryVO questionSubmitQueryVO) {
        if (questionSubmitQueryVO == null) {
            return null;
        }
        QuestionSubmit questionSubmit = new QuestionSubmit();
        BeanUtils.copyProperties(questionSubmitQueryVO, questionSubmit);
        QuestionVO questionVO = questionSubmitQueryVO.getQuestionVO();
        if (questionVO != null) {
            questionSubmit.setQuestionId(questionVO.getId());
        }
        UserVO userVO = questionSubmitQueryVO.getUserVO();
        if (userVO != null) {
            questionSubmit.setUserId(userVO.getId());
        }
        JudgeInfo judgeInfo = questionSubmitQueryVO.getJudgeInfo();
        if (judgeInfo != null) {
            questionSubmit.setJudgeInfo(JSONUtil.toJsonStr(questionSubmitQueryVO.getJudgeInfo()));
        }
        return questionSubmit;
    }

    /**
     * 对象转包装类
     *
     * @param questionSubmit
     * @return
     */
    // User和Question属性没有转换，需要在业务层实现
    public static QuestionSubmitQueryVO objToVo(QuestionSubmit questionSubmit) {
        if (questionSubmit == null) {
            return null;
        }
        QuestionSubmitQueryVO questionSubmitQueryVO = new QuestionSubmitQueryVO();
        BeanUtils.copyProperties(questionSubmit, questionSubmitQueryVO);
        String judgeInfo = questionSubmit.getJudgeInfo();
        if (judgeInfo != null) {
            questionSubmitQueryVO.setJudgeInfo(JSONUtil.toBean(judgeInfo, JudgeInfo.class));
        }
        return questionSubmitQueryVO;
    }


    private static final long serialVersionUID = 1L;
}